<template>
    <div>
        <basic-container>
            <avue-crud
                    :data="list"
                    :option="option"
                    ref="crud"
                    v-model="form"
                    @on-load="getList"
                    :table-loading="listLoading"
                    :page="page"
                    @refresh-change="handleRefreshChange"
                    @row-del="deletes"
                    >
            </avue-crud>
        </basic-container>
    </div>
</template>

<script>
    import {pageLog,deleteLog} from "@/api/log";
    import {tableOption} from '@/const/log';
    import {mapGetters} from "vuex";

    export default {
        data() {
            return {
                page: {
                    total: 0, // 总页数
                    currentPage: 1, // 当前页数
                    pageSize: 10, // 每页显示多少条,
                    isAsc: false//是否倒序
                },
                listLoading: false,
                list: [],
                option: tableOption,
                roles: [],
                form: {},
                role: [],
                rolesOptions: [],
                treeDeptData:[],
                defaultProps: {
                    label: "name",
                    value: 'id'
                }
            }
        },
        computed: {
            ...mapGetters(["permissions"])
        },
        methods: {
            //获取分页数据
            getList(page, params) {
                this.listLoading = true;
                pageLog(Object.assign({
                    current: page.currentPage,
                    size: page.pageSize
                }, params)).then(response => {
                    this.list = response.data.data.records
                    this.page.total = response.data.data.total
                    this.listLoading = false;
                })
            },
            deletes(row,index){
                this.$confirm(
                    "此操作将永久删除该记录, 是否继续?",
                    "提示",
                    {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning"
                    }
                ).then(() =>{
                    deleteLog(row.id).then(() =>{
                        this.list.splice(index, 1);
                        this.$notify({
                            title: "成功",
                            message: "删除成功",
                            type: "success",
                            duration: 2000
                        });
                        this.getList(this.page);
                    }) .cache(() => {
                        this.$notify({
                            title: "失败",
                            message: "删除失败",
                            type: "error",
                            duration: 2000
                        });
                    });
                })
            },
            handleFilter(param) {
                this.page.page = 1;
                this.getList(this.page, param);
            },
            handleRefreshChange() {
                this.getList(this.page)
            }
        }
    }
</script>
